// find the largest file 
var fs = require('fs');

module.exports = function(dir, cb) {
	fs.readdir(dir, function(err, list) {
		if (err) {
			return cb(err);
		}

		var name = '';
		var size = 0;

		list.forEach(function(item, index, arr) {
			var path = dir + item; // path.join(dir,item)
			fs.stat(path, function(err, stats) {
				if (err) {
					return cb(err);
				}

				if (stats.isFile() && stats.size > size) {
					name = item;
					size = stats.size;
				}

				if (index == list.length - 1) {
					// console.log('name=' + name + ', size=' + size);
					cb(null, {
						name: name,
						size: size
					});
				}
			});
		});
	});
}